//
//  ViewController.m
//  Runtime归档解档
//
//  Created by youmy on 2018/1/15.
//  Copyright © 2018年 youmy. All rights reserved.
//

#import "ViewController.h"
#import "Person.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    Person * p = [[Person alloc] init];
    p.name = @"Tom";
    p.age = 28;
    
    // 归档路径
    NSString * path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    
    NSString * filePath = [path stringByAppendingPathComponent:@"archiver_person"];
    
    // 归档
    BOOL result = [NSKeyedArchiver archiveRootObject:p toFile:filePath];
    
    if (result) {
        NSLog(@"归档成功");
    }else{
        NSLog(@"归档失败");
    }
    
    // 解档
    Person * p1 = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
    NSLog(@"%@", p1.name);
}



@end
